package com.weitu.util;

/**
 * @author LiMeng 2016/11/30
 */
public class AjaxResult {
    private String message;
    private Boolean success;
    private Object data;

    public AjaxResult() {
        this.message = "操作失败！";
        this.success = false;
    }

    public AjaxResult(String message) {
        this.message = message;
        this.success = true;
    }

    public AjaxResult(String message, Boolean success) {
        this.message = message;
        this.success = success;
    }

    public AjaxResult(String message, Boolean success, Object data) {
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public static AjaxResult success(String message) {
        return new AjaxResult(message);
    }

    public static AjaxResult success(String message, Object data) {
        return new AjaxResult(message, true, data);
    }

    public static AjaxResult fail(String message) {
        return new AjaxResult(message, false);
    }

    public static AjaxResult fail(String message, Object data) {
        return new AjaxResult(message, false, data);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("AjaxResult{");
        sb.append("message='").append(message).append('\'');
        sb.append(", success=").append(success);
        sb.append(", data=").append(data);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AjaxResult)) return false;

        AjaxResult that = (AjaxResult) o;

        if (!getMessage().equals(that.getMessage())) return false;
        if (!getSuccess().equals(that.getSuccess())) return false;
        return getData() != null ? getData().equals(that.getData()) : that.getData() == null;
    }

    @Override
    public int hashCode() {
        int result = getMessage().hashCode();
        result = 31 * result + getSuccess().hashCode();
        result = 31 * result + (getData() != null ? getData().hashCode() : 0);
        return result;
    }
}
